<%@page import="com.healtyprj.Constants"%>
<%@page import="com.healtyprj.Goal2"%>
<%@page import="com.healtyprj.rsa.RsaUtils"%>
<%@page import="com.healtyprj.Goal"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.amazonaws.util.json.JSONArray"%>
<%@page import="java.util.List"%>
<%@page import="com.amazonaws.services.dynamodb.datamodeling.DynamoDBQueryExpression"%>
<%@page import="com.healtyprj.Weight"%>
<%@page import="com.healtyprj.User"%>
<%@page import="com.amazonaws.util.json.JSONObject"%>
<%@page import="org.springframework.util.StringUtils"%>
<%@page import="com.amazonaws.services.dynamodb.datamodeling.DynamoDBMapper"%>
<%@page import="com.amazonaws.services.dynamodb.model.PutItemResult"%>
<%@page import="com.amazonaws.services.dynamodb.model.PutItemRequest"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.HashMap"%>
<%@page import="com.amazonaws.services.dynamodb.model.AttributeValue"%>
<%@page import="com.amazonaws.AmazonServiceException"%>
<%@page import="com.amazonaws.services.dynamodb.model.TableStatus"%>
<%@page import="com.amazonaws.services.dynamodb.model.DescribeTableRequest"%>
<%@page import="com.amazonaws.services.dynamodb.model.TableDescription"%>
<%@page import="com.amazonaws.services.dynamodb.model.ProvisionedThroughput"%>
<%@page import="com.amazonaws.services.dynamodb.model.KeySchemaElement"%>
<%@page import="com.amazonaws.services.dynamodb.model.KeySchema"%>
<%@page import="com.amazonaws.services.dynamodb.model.CreateTableRequest"%>
<%@page import="com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider"%>
<%@page import="com.amazonaws.services.dynamodb.AmazonDynamoDBClient"%>
<%@page import="com.amazonaws.services.dynamodb.AmazonDynamoDB"%>
<%@ page language="java" contentType="text/x-json; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
String name = "薫";
String startDate = "2013/1/1";
String finishDate = "2013/1/1";
String weight = "水曜どうでしょう？";
AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
dynamoDB.setEndpoint(Constants.REGION);

DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(dynamoDB);
Goal2 goal = new Goal2();
RsaUtils utils = new RsaUtils(application.getRealPath("/") + "/pkey.pk8", application.getRealPath("/") + "/publicKey.der");
goal.setName(name);
goal.setStartDate(startDate);
goal.setFinishDate(finishDate);
goal.setWeight(utils.encryptWithPrivateKey(weight.getBytes("UTF-8")));
dynamoDBMapper.save(goal);

JSONObject json = new JSONObject();
DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression(
		new AttributeValue().withS(name));
List<Goal2> goals = dynamoDBMapper.query(Goal2.class, queryExpression);
out.println(new String(weight.getBytes("UTF-8"), "UTF-8"));
for (Goal2 goal1 : goals) {
	out.println("復号前：" + goal1.getWeight());
	out.println("復号後：" + utils.decryptWithPublicKey(goal1.getWeight()));
}
%>